﻿using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 基于WPF的电缆采样数据分析系统.Service;

namespace 基于WPF的电缆采样数据分析系统.ViewModels.TDRWork.MenuPage
{
    public class SelectTheColumnsToDisplayUCViewModel : BindableBase, IDialogHostAware
    {
        // 主机名
        private const string DialogHostName = "RootDialog";


        #region 确定
        /// <summary>
        /// 确定命令
        /// </summary>
        public DelegateCommand SaveCommand { get; set; }

        /// <summary>
        /// 确定方法
        /// </summary>
        private void SaveFun()
        {
            if (DialogHost.IsDialogOpen(DialogHostName))
            {

                DialogParameters paras = new DialogParameters();
                paras.Add("IndexChecked", IndexChecked);
                paras.Add("UserChecked", UserChecked);
                paras.Add("TimeChecked", TimeChecked);
                paras.Add("OperateDescriptionChecked", OperateDescriptionChecked);

                DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.Yes, paras));
            }
        }
        #endregion


        #region 取消
        /// <summary>
        /// 取消命令
        /// </summary>
        public DelegateCommand CancelCommand { get; set; }

        /// <summary>
        /// 取消方法
        /// </summary>
        private void CancelFun()
        {
            if (DialogHost.IsDialogOpen(DialogHostName))
            {
                DialogHost.Close(DialogHostName, new DialogResult(ButtonResult.No));
            }
        }
        #endregion


        /// <summary>
        /// 打开过程中
        /// </summary>
        /// <param name="parameters"></param>
        public void OnDialogOpening(IDialogParameters parameters)
        {
            PageTitle = parameters.GetValue<string>("Title");

            var list = parameters.GetValue<List<bool>>("list");

            // 索引号
            if (list[0])
            {
                IndexChecked = true;
            } else
            {
                IndexChecked = false;
            }

            // 用户
            if (list[1])
            {
                UserChecked = true;
            }
            else
            {
                UserChecked = false;
            }

            // 时间
            if (list[2])
            {
                TimeChecked = true;
            }
            else
            {
                TimeChecked = false;
            }

            // 操作描述
            if (list[3])
            {
                OperateDescriptionChecked = true;
            }
            else
            {
                OperateDescriptionChecked = false;
            }
        }

        /// <summary>
        /// 构造器
        /// </summary>
        public SelectTheColumnsToDisplayUCViewModel()
        {
            //绑定确定和取消命令
            SaveCommand = new DelegateCommand(SaveFun);
            CancelCommand = new DelegateCommand(CancelFun);
        }


        #region 页面信息
        /// <summary>
        /// 标题
        /// </summary>
        private string _PageTitle;

        /// <summary>
        /// 标题
        /// </summary>
        public string PageTitle
        {
            get { return _PageTitle; }
            set
            {
                _PageTitle = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 索引号是否选中
        /// </summary>
        private bool _IndexChecked;

        /// <summary>
        /// 索引号是否选中
        /// </summary>
        public bool IndexChecked
        {
            get { return _IndexChecked; }
            set { 
                _IndexChecked = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 用户是否选中
        /// </summary>
        private bool _UserChecked;

        /// <summary>
        /// 用户是否选中
        /// </summary>
        public bool UserChecked
        {
            get { return _UserChecked; }
            set { 
                _UserChecked = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// 时间是否选中
        /// </summary>
        private bool _TimeChecked;

        /// <summary>
        /// 时间是否选中
        /// </summary>
        public bool TimeChecked
        {
            get { return _TimeChecked; }
            set { 
                _TimeChecked = value;
                RaisePropertyChanged();
            }
        }


        /// <summary>
        /// 操作描述是否选中
        /// </summary>
        private bool _OperateDescriptionChecked;

        /// <summary>
        /// 操作描述是否选中
        /// </summary>
        public bool OperateDescriptionChecked
        {
            get { return _OperateDescriptionChecked; }
            set {
                _OperateDescriptionChecked = value;
                RaisePropertyChanged();
            }
        }


        #endregion
    }
}
